package com.qiudaozhang.jblog.frontend.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.qiudaozhang.jblog.article.service.TagService;
import com.qiudaozhang.jblog.model.Article;
import com.qiudaozhang.jblog.article.service.CategoryService;
import com.qiudaozhang.jblog.model.Tag;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author 邱道长
 * 时间： 2018/12/25 11:26
 */
@Controller
@RequestMapping("category")
public class CategoryController {

    @Reference(url = "${article.service.provider.url}", version = "${service.version}", group = "${dubbo.group}")
    private CategoryService categoryService;
    
    @Reference(url = "${article.service.provider.url}", version = "${service.version}", group = "${dubbo.group}")
    private TagService tagService;

    /**
     * 根据分类信息查询文章
     * @param categoryId
     * @return
     */
    @RequestMapping("get/{categoryId}")
    public String get(@RequestParam(name = "pageNum",required = false) Integer pageNum, @RequestParam(name = "pageSize",required = false) Integer pageSize,
                      @PathVariable("categoryId") Integer categoryId , Model model){
        if(pageNum == null)
            pageNum = 1;
        if(pageSize == null)
            pageSize = 10;
        PageInfo<Article> pageInfo = categoryService.queryArticlePageByCategoryId(pageNum,pageSize,categoryId);
        model.addAttribute("p",pageInfo);
        model.addAttribute("categoryId",categoryId);
        model.addAttribute("categories",categoryService.selectAll());
        model.addAttribute("tags",tagService.selectAll());
        return "category/list";
    }
}









